/*
 * @Descripttion: 
 * @Date: 2021-05-06 16:52:54
 * @LastEditTime: 2021-05-07 08:13:49
 * @FilePath: /vue_demo/src/directives/enterNumber/index.js
 * @input只输入数字
 */
const enterNumber = {
  inserted: (el) => {
    el.addEventListener("keypress", e=>{
      e = e || window.event
      let charcode = typeof e.charCode === 'number' ? e.charCode : e.kerCode
      let re = /\d/
      if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey) {
        if(e.preventDefault) {
          e.preventDefault()
        }else {
          e.returnValue = false
        }
      }
    })
  },
  unbind: (el) => {
    el.removeEventListener("keypress", el.handler)
  }
}

export default enterNumber